<?php

if( ! defined('DOCROOT') )
{
    require_once '/var/www/advancelab/chilik2/unittest/bootstrap.php';
}

class ViewTest extends UnitTestCase
{
    function testingNoZoneView()
    {
        $request = new Core\MVCRequest();
        $result = new Entity\MvcResult();
        
        $view = new TestNoZoneView( $request, $result );
        
        try
        {
            $response = $view->createResponse();
        }
        catch( Exception $e )
        {
            $this->assertEqual( 'No Zones are defined in the view !', $e->getMessage() );
        }
    }
    
    function testingFaultyView()
    {
        $request = new Core\MVCRequest();
        $result = new Entity\MvcResult();
        
        $view = new TestFaultyView( $request, $result );
        
        try
        {
            $response = $view->createResponse();
        }
        catch( Entity\BaseException $e )
        {
            $this->assertEqual( 'The value [ O:8:"stdClass":0:{} ] that you were trying to assign to setting "zone" is invalid Allowed values are: instance of Base\ViewHandler.', $e->getMessage() );
        }
    }
    
    function testingTwoViews()
    {
        $request = new Core\MVCRequest();
        $result = new Entity\MvcResult();
        $result->variables = array( 'var1' => 42 );
        
        $view = new TestTwoView( $request, $result );
        $response = $view->createResponse();
        
        $obj1 = new stdClass();
        $obj1->vars = array( 'var1' => 42 );
        
        $obj2 = clone $obj1;
        $obj2->vars['name1'] = $obj1;
        
        $obj1->name = 'name1';
        $obj2->name = 'name2';
        
        $this->assertEqual( $obj2, $response->body );
    }
    
    function testingOneViews()
    {
        $request = new Core\MVCRequest();
        $result = new Entity\MvcResult();
        $result->variables = array( 'var1' => 42 );
        
        $view = new TestOneView( $request, $result );
        $response = $view->createResponse();
        
        $obj1 = new stdClass();
        $obj1->vars = array( 'var1' => 42 );
        
        $obj1->name = 'name';
        
        $this->assertEqual( $obj1, $response->body );
    }
    
}
